// Problem: CF1672C Unequal Array
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/CF1672C
// Memory Limit: 250 MB
// Time Limit: 1000 ms

#include <iostream>
#include <cstdio>
using namespace std;
const int N=2e5+5;
int a[N];
int main(){
	int t,n;
	cin>>t;
	while(t--){
		cin>>n;
		int cnt=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		int l=n,r=1;
		for(int i=2;i<=n;i++){
			if(a[i]==a[i-1]){
				l=min(l,i-1);
				r=max(r,i);
				cnt++;
			} 
		}
		int len=r-l-1;
		if(cnt<=1) cout<<0<<endl;
		else if(len==1) cout<<1<<endl;
		else cout<<len-1<<endl;
		
	}
	return 0;
}